package cn.vshare.controller;

import cn.vshare.entity.Tips;
import cn.vshare.service.TipsService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

@RestController
public class TipsController {

    @Autowired
    private TipsService tipsService;

    @RequestMapping("/getTips")
    public Map<String,Object> getTips(String info){
        JSONObject jsonObject = JSON.parseObject(info); //将条件转换成json对象
        Map<String,Object> map = new HashMap<String, Object>();
        Page<Tips> tipsPage = tipsService.getTips(jsonObject); //查询举报信息
        map.put("tipsList",tipsPage);
        map.put("totalPage",tipsPage.getPages()); //添加总页数
        map.put("currPage",jsonObject.get("currPage")); //添加当前页
        map.put("totalRows",tipsPage.getTotal()); //添加总行数
        return map;
    }

    /**
     * 处理举报信息
     * @return
     */
    @RequestMapping("/handleTips")
    public String handleTips(String condition){
        System.out.println(condition);
        JSONObject jsonObject = JSON.parseObject(condition); //将条件转换成json对象
        tipsService.handleTips(jsonObject);
        return "success";
    }

    /**
     * 跳转页面
     * @return
     */
    @RequestMapping("/forwordTips")
    public ModelAndView forwordTips(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("h-ui/system-tips");
        return modelAndView;
    }



    public TipsService getTipsService() {
        return tipsService;
    }

    public void setTipsService(TipsService tipsService) {
        this.tipsService = tipsService;
    }
}
